{% extends 'AdminBundle::layout.html.twig' %}


    {% block title %}{% if data.id == 0 %}添加帐号{% else %}编辑帐号{% endif %}{% endblock %}

    {% block css %}
        <style>
            .com-list-box{
                width: 725px;
            }
            .display{
                width: 100%;
            }
        </style>
    {% endblock %}


    {% block top %}
        {#{{ dump() }}#}
        {{ parent() }}
    {% endblock %}



    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}

    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">账号管理</span>
            </div>
            <div class="top-nav">普通管理员账号管理</div>
            <span class="r-arrow top-r-arrow"></span>
            <div class="top-nav top-nav-active">{% if data.id == 0 %}添加{% else %}编辑{% endif %}</div>
        </div>
        <div class="main-content">
            <div class="mes-content">

                <div class="main-mes-content">
                    <form id="comMesBtn">
                        <div class="com-list">
                            <div class="com-list-box">
                                <div class="com-left fl" style="line-height: 18px;">管理员账号<br>(手机号码)</div>
                                <input type="text" name="phone" {% if data.id > 0 %}readonly value="{{ data.phone }}" {% endif %}  class="is-change pop-com-input input-phone" placeholder="请输入管理员账号/手机号码">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">管理员姓名</div>
                                <input type="text" name="name" value="{% if data.id > 0 %}{{ data.realname }}{% endif %}" class="is-change pop-com-input input-name" placeholder="请输入管理员姓名">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">邮箱</div>
                                <input type="text" name="email" value="{% if data.id > 0 %}{{ data.email }}{% endif %}" class="is-change pop-com-input input-email" placeholder="请输入邮箱地址">
                            </div>

                            <div class="com-list-box">
                                <div class="com-left fl">管理员名称</div>
                                <input type="text" name="admin_name" value="{% if data.id > 0 %}{{ data.nickname }}{% endif %}" class="is-change pop-com-input input-nickname" placeholder="请输入管理员名称">
                            </div>

                            <div class="display">
                                <div class="com-list-box fl">
                                    <div class="com-left fl">身份属性</div>
                                    <div class="select-jurisdiction fl">
                                        <span class="radio-icon {% if data.id > 0 %}{% if data.admin_role_id == 3 %}radio-icon-check{% endif %}{% else %}{% endif %} fl" data-value="3"></span>
                                        <span class="file-text fl">普通管理员</span>
                                    </div>

                                    <div class="select-jurisdiction fl">
                                        <span class="radio-icon fl {% if data.id > 0 and data.admin_role_id == 4 %}radio-icon-check{% endif %}" data-value="4"></span>
                                        <span class="file-text fl">科技载体管理员</span>
                                    </div>
                                </div>
                                <div class="clearfix"></div>
                            </div>

                            <div class="clearfix"></div>
                            <div class="add-mem-box" style="margin-top: 40px;">
                                <div class="com-left fl"></div>
                                <div class="acc-opera-btn fl mem-btn p-first-btn">保存</div>
                                <a href="{{ path('account_list_index') }}" class="acc-opera-btn fl mem-cancel">取消</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}


{% block box %}
{% endblock %}


{% block javascript %}
<script type="text/javascript">
    $(function () {

        SidebarHighlighting('7');

        SonSidebar('7', '1');


        // 属性选择
        $('.radio-icon').on('click', function () {
            {% if data.id == 0 %}
            $('.radio-icon').removeClass('radio-icon-check');
            $(this).addClass('radio-icon-check');
            {% else %}
            popStatus(2, '不可修改身份属性', 1, '', true);
            {% endif %}
        });


        // 点击保存
        $('.p-first-btn').on('click', function() {

            var name = $(".input-name").val();
            var email = $(".input-email").val();
            var nickname = $(".input-nickname").val();



            {% if data.id == 0 %}
                var phone = $(".input-phone").val();
                var admin_role = $(".radio-icon-check").data("value");

                if ($.trim(phone) == '') {
                    popStatus(2, '请输入手机号码', 1, '', true);
                    return;
                }

                if(!(/^1[3|4|5|7|8]\d{9}$/.test(phone))){
                    popStatus(2, '手机号码格式错误', 1,'', true);
                    return;
                }

                if(admin_role == null){
                    popStatus(2, '请选择身份属性', 1, '', true);
                    return;
                }
            {% endif %}


            if ($.trim(name) == '' || $.trim(email) == '' || $.trim(nickname) == '') {
                popStatus(2, '请填写完整', 1, '', true);
                return;
            }

            var id = "{{ data.id }}";

            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;

            if(!myreg.test(email)) {
                popStatus(2, '请输入有效的邮箱', 1, '', true);
                return;
            }

            var prame = {nickname:nickname,realname:name,email:email,id:id};

            {% if data.id == 0 %}
            prame.phone = phone;
            prame.admin_role_id = admin_role;
            prame.district_id = "{{ data.super_district_id }}";

            {% endif %}

            $.post("{{ path('api_admin_edit_admin_account') }}",prame,function(data){
                console.log(data);
                if(data.errorCode == 0){
                    popStatus(1, data.message, 1, "{{ path('account_list_index') }}", true);
                } else {
                    popStatus(2, data.message, 1, '', true);
                }


            })

        })

    })
</script>
{% endblock %}